package com.kmt.plaza.config;

import org.apache.ibatis.annotations.Select;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    //swagger会帮助我们生成接口文档
    /*
    * 1.配置生成的文档信息
    * 2.配置生成规则
    * */
    //Docket封装接口文档信息
    @Bean
    public Docket getDocket(){
        //创建封面信息对象
        ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();
        apiInfoBuilder.title("《唯易购》后端接口说明")
                .description("该文档详细说明了唯易购电商项目后端接口规范...")
                .version("v 2.0.1")
                .contact(new Contact("枯木堂","www.kmt.com","2658994493@qq.com"));

        ApiInfo apiInfo = apiInfoBuilder.build();
        //如何获取一个接口对象
        //new接口，需要在构造器后的{}实现接口中的所有抽象方法
        //new 子类/实体类
        //SqlSessionFactory工厂模式
        //指定文档风格
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
               .apiInfo(apiInfo)//指定生成的文档中的封面信息：文档标题、版本、作者
               .select()
               .apis(RequestHandlerSelectors.basePackage("com.kmt.plaza.controller"))
               .paths(PathSelectors.any())
               .build();
        return docket;
    }
}
